home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / LOGO.H < prev    next >
C/C++ Source or Header  |  1993-09-27  |  14KB  |  420 lines

  1. /*
  2.  *      logo.h          logo header file                dvb
  3.  *
  4.  *    Copyright (C) 1989 The Regents of the University of California
  5.  *    This Software may be copied and distributed for educational,
  6.  *    research, and not for profit purposes provided that this
  7.  *    copyright and statement are included in all such copies.
  8.  *
  9.  */
  10.  
  11. /* #define ecma    /* for European extended character set using parity bit */
  12.  
  13. /* #define unix   /* This should be done automatically by gcc! */
  14. /* #define ultrix /* no usleep */
  15.  
  16. #ifdef THINK_C
  17. #define mac
  18. #endif
  19.  
  20. #ifdef __TURBOC__
  21. #define ibm
  22. #endif
  23.  
  24. #ifdef __ZTC__
  25. #define ibm
  26. #endif
  27.  
  28. #ifdef unix
  29. #ifndef NOGRAPH
  30. #define x_window    /* turn this off for no graphics */
  31. #endif
  32. #endif
  33.  
  34. #ifdef vax
  35. #define bsd
  36. #endif
  37.  
  38. #ifdef sun
  39. #define bsd
  40. #endif
  41.  
  42. /* #define SYSV */    /* turn this on for inferior AT&T brand Unix */
  43.  
  44. #include <stdio.h>
  45. #include <string.h>
  46. #include <signal.h>
  47. #ifndef mips
  48. #include <stdlib.h>
  49. #else
  50. #include <sys/types.h>
  51. #include <malloc.h>
  52. extern char *getenv();
  53. #endif
  54.  
  55. #ifdef ibm
  56. #include <dos.h>
  57. #endif
  58.  
  59. #ifdef mac
  60. #define check_throwing (check_mac_stop() || stopping_flag == THROWING)
  61. #else
  62. #ifdef ibm
  63. #define check_throwing (check_ibm_stop() || stopping_flag == THROWING)
  64. #else
  65. #define check_throwing (stopping_flag == THROWING)
  66. #endif
  67. #endif
  68.  
  69. typedef enum {wrapmode, fencemode, windowmode} mode_type;
  70.  
  71. #define WORDSIZE    32    /* bits per int */
  72.  
  73. #define NIL             (NODE *) 0
  74. #define UNBOUND         Unbound
  75. #define UNDEFINED       Unbound
  76. #define END_OF_LIST     (NODE *) 2
  77. #define HASH_LEN        1021    /* a prime number */
  78. #define SEG_SIZE        1000 /* 1 for debugging internal leaks */
  79. //#define MAX_PHYS_LINE   5000
  80. //#define GCMAX        8192
  81. #define MAX_NUMBER      50    /* max number of digits in a float */
  82. #define MAX_BUFFER_SIZE 256
  83. #define PREFIX_PRIORITY 2
  84. #define MACRO_PRIORITY    1
  85. #define TAIL_PRIORITY    0
  86.  
  87. typedef short NODETYPES;
  88.  
  89. /* Note that some of these values are used twice; they must be
  90.  * distinguishable by the other bits used with them. */
  91.  
  92. #define NT_TREE           (NODETYPES)0100000
  93. #define NT_EMPTY    (NODETYPES)040000
  94. #define NT_AGGR        (NODETYPES)020000
  95. #define NT_LIST        (NODETYPES)010000
  96. #define NT_RUNP        (NODETYPES)004000
  97. #define NT_ARRAY    (NODETYPES)002000
  98. #define NT_WORD        (NODETYPES)001000
  99. #define NT_NUMBER    (NODETYPES)000400
  100. #define NT_FLOAT    (NODETYPES)000200
  101. #define NT_CONT         (NODETYPES)000200
  102. #define NT_PRIM        (NODETYPES)000100
  103. #define NT_INFIX    (NODETYPES)000040
  104. #define NT_LINE            (NODETYPES)000040
  105. #define NT_VBAR        (NODETYPES)000040
  106. #define NT_STRING    (NODETYPES)000020
  107. #define NT_BACKSL    (NODETYPES)000010
  108. #define NT_PUNCT    (NODETYPES)000004
  109. #define NT_TAILFORM    (NODETYPES)000004
  110. #define NT_COLON    (NODETYPES)000002
  111. #define NT_MACRO        (NODETYPES)000002
  112. #define NT_CASEOBJ    (NODETYPES)000001
  113.  
  114. #define    PNIL        (NODETYPES)(NT_EMPTY|NT_AGGR|NT_LIST)
  115. #define PUNBOUND    (NODETYPES)0
  116. #define CONS        (NODETYPES)(NT_AGGR|NT_LIST)
  117. #define STRING        (NODETYPES)(NT_WORD|NT_STRING)
  118. #define INT        (NODETYPES)(NT_WORD|NT_NUMBER)
  119. #define FLOAT        (NODETYPES)(NT_WORD|NT_NUMBER|NT_FLOAT)
  120. #define PRIM        (NODETYPES)(NT_PRIM)
  121. #define MACRO        (NODETYPES)(NT_PRIM|NT_MACRO)
  122. #define TAILFORM    (NODETYPES)(NT_PRIM|NT_TAILFORM)
  123. #define CASEOBJ        (NODETYPES)(NT_WORD|NT_CASEOBJ)
  124. #define INFIX        (NODETYPES)(NT_PRIM|NT_INFIX)
  125. #define TREE        (NODETYPES)(NT_AGGR|NT_LIST|NT_TREE)
  126. #define RUN_PARSE    (NODETYPES)(NT_AGGR|NT_LIST|NT_RUNP)
  127. #define QUOTE        (NODETYPES)(NT_WORD|NT_PUNCT)
  128. #define COLON        (NODETYPES)(NT_WORD|NT_PUNCT|NT_COLON)
  129. #define BACKSLASH_STRING (NODETYPES)(NT_WORD|NT_STRING|NT_BACKSL)
  130. #define VBAR_STRING    (NODETYPES)(NT_WORD|NT_STRING|NT_BACKSL|NT_VBAR)
  131. #define ARRAY        (NODETYPES)(NT_AGGR|NT_ARRAY)
  132. #define LINE        (NODETYPES)(NT_LINE|NT_LIST|NT_AGGR)
  133. #define CONT        (NODETYPES)(NT_CONT|NT_LIST)
  134. #define aggregate(nd)    (nodetype(nd) & NT_AGGR)
  135. #define is_cont(nd)    (nodetype(nd) == CONT)
  136. #define is_list(nd)    (nodetype(nd) & NT_LIST)
  137. #define is_tree(nd)    (nodetype(nd) & NT_TREE)
  138. #define is_string(nd)    (nodetype(nd) & NT_STRING)
  139. #define is_number(nd)    (nodetype(nd) & NT_NUMBER)
  140. #define is_prim(nd)    (nodetype(nd) & NT_PRIM)
  141. #define is_word(nd)    (nodetype(nd) & NT_WORD)
  142. #define runparsed(nd)    (nodetype(nd) & NT_RUNP)
  143. #define backslashed(nd)    (nodetype(nd) & NT_BACKSL)
  144. #define is_tailform(nd)    (nodetype(nd) == TAILFORM)
  145.  
  146. typedef enum { FATAL, OUT_OF_MEM, STACK_OVERFLOW, TURTLE_OUT_OF_BOUNDS,
  147.               BAD_DATA_UNREC, DIDNT_OUTPUT, NOT_ENOUGH, BAD_DATA, TOO_MUCH,
  148.               DK_WHAT, PAREN_MISMATCH, NO_VALUE, UNEXPECTED_PAREN, DK_HOW,
  149.             NO_CATCH_TAG, ALREADY_DEFINED, STOP_ERROR, ALREADY_DRIBBLING,
  150.             FILE_ERROR, IF_WARNING, SHADOW_WARN, USER_ERR, IS_PRIM,
  151.             NOT_INSIDE, DK_HOW_UNREC, NO_TEST, UNEXPECTED_BRACKET,
  152.             UNEXPECTED_BRACE, BAD_GRAPH_INIT, ERR_MACRO,
  153.             DK_WHAT_UP, AT_TOPLEVEL, APPLY_BAD_DATA} ERR_TYPES;
  154.  
  155. typedef int BOOLEAN;
  156.  
  157. #define FALSE    0
  158. #define TRUE    1
  159.  
  160. #define even_p(x) !(x & 0x1)
  161.  
  162. #define FIXNUM          long
  163. #define FLONUM          double
  164. #define MAXINT        0x7fffffffL
  165. #define SAFEINT        0x00003fff  /* safe to multiply w/o overflow */
  166.  
  167. typedef struct logo_node {
  168.     NODETYPES node_type;
  169. /*    char gc_flags;    */
  170.     short ref_count;
  171.     union {
  172.         struct {
  173.             struct logo_node *ncar;
  174.             struct logo_node *ncdr;
  175.             struct logo_node *nobj;         /* used only for oblist */
  176.         } ncons;
  177.         struct {
  178.             char *nstring_ptr;
  179.             char *nstring_head;
  180.             int nstring_len;
  181.         } nstring;
  182.         struct {
  183.             struct logo_node * (*nprim_fun) ();
  184.             short npriority;
  185.             short nmin_args;
  186.             short ndef_args;
  187.             short nmax_args;
  188.         } nprim;
  189.         FIXNUM nint;
  190.         FLONUM nfloat;
  191.         struct {
  192.             int narray_dim;
  193.             int narray_origin;
  194.             struct logo_node **narray_data;
  195.         } narray;
  196.     } nunion;
  197. } NODE;
  198.  
  199. #define settype(node, type)     ((node)->node_type = (type))
  200.  
  201. #define getrefcnt(node)         ((node)->ref_count)
  202. #define setrefcnt(node,val)     ((node)->ref_count = (val))
  203. #define increfcnt(node)         (((node)->ref_count)++)
  204. #define decrefcnt(node)         (--((node)->ref_count))
  205.  
  206. #define n_car                   nunion.ncons.ncar
  207. #define n_cdr                   nunion.ncons.ncdr
  208. #define n_obj                   nunion.ncons.nobj
  209. #define getobject(node)         ((node)->n_obj)
  210. #define car(node)               ((node)->n_car)
  211. #define cdr(node)               ((node)->n_cdr)
  212. #define caar(node)              ((node)->n_car->n_car)
  213. #define cadr(node)              ((node)->n_cdr->n_car)
  214. #define cdar(node)              ((node)->n_car->n_cdr)
  215. #define cddr(node)              ((node)->n_cdr->n_cdr)
  216.  
  217. #define n_str                   nunion.nstring.nstring_ptr
  218. #define n_len                   nunion.nstring.nstring_len
  219. #define n_head                  nunion.nstring.nstring_head
  220. #define getstrptr(node)         ((node)->n_str)
  221. #define getstrlen(node)         ((node)->n_len)
  222. #define getstrhead(node)        ((node)->n_head)
  223. #define setstrptr(node,ptr)     ((node)->n_str = (ptr))
  224. #define setstrlen(node,len)     ((node)->n_len = (len))
  225. #define setstrhead(node,ptr)    ((node)->n_head = (ptr))
  226.  
  227. #define getstrrefcnt(sh)        (*sh)
  228. #define setstrrefcnt(sh, v)     (*sh = (v))
  229. #define incstrrefcnt(sh)        ((*sh)++)
  230. #define decstrrefcnt(sh)        (--(*sh))
  231.  
  232. #define n_int                   nunion.nint
  233. #define getint(node)            ((node)->n_int)
  234. #define setint(node,num)        ((node)->n_int = (num))
  235.  
  236. #define n_float                 nunion.nfloat
  237. #define getfloat(node)          ((node)->n_float)
  238. #define setfloat(node,num)      ((node)->n_float = (num))
  239.  
  240. #define n_pfun                  nunion.nprim.nprim_fun
  241. #define n_ppri                  nunion.nprim.npriority
  242. #define n_pmin                  nunion.nprim.nmin_args
  243. #define n_pdef                  nunion.nprim.ndef_args
  244. #define n_pmax                  nunion.nprim.nmax_args
  245. #define getprimfun(node)        ((node)->n_pfun)
  246. #define setprimfun(node,fun)    ((node)->n_pfun = (fun))
  247. #define getprimmin(node)        ((node)->n_pmin)
  248. #define setprimmin(node,num)    ((node)->n_pmin = (num))
  249. #define getprimmax(node)        ((node)->n_pmax)
  250. #define setprimmax(no